package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper um;

    /**
     * 用户注册登入
     *
     * @param user
     * @return
     */
    @Override
    public int add(User user) {
        return um.insert(user);
    }

    /**
     * 根据手机号查找这个用户在不在
     *
     * @param phone
     * @return
     */
    @Override
    public User findByPhone(String phone) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getPhone, phone);
        User user = um.selectOne(lqw);
        return user;
    }
}
